(function () {
    var form = layui.form;
    form.verify({
        checkUserName:function (value) {
            if(value.length == 0){
                return "用户名不能为空";
            }
        },
        checkPassword:function (value) {
            if (value.length == 0 ) {
                return "密码不能为空";
            }
        },
        checkVerify:function (value) {
            if(value.length == 0){
                return "验证码不能为空";
            }
        }
    });
    form.on('submit(loginForm)', function(data){
        var $ = layui.$;
        $.ajax({
            url:"user/login/"+data.field.userName+"/"+data.field.userPwd+"/"+data.field.verifyCode,
            method:"get",
            success:function (data) {
                if(data.code == 200){
                   layui.layer.msg(data.msg, {icon: 1})
                    setTimeout(function () {
                        window.location.href = "http://localhost:8080/BWM_war/index.html";
                    },1000)
                }else if(data.code == 500){
                    layui.layer.alert(data.msg, {icon: 2});
                }
            },
            error:function (data) {
                console.log(data);
            }
        });
        return false;
    });

})();
function changeCode() {
    //加载layui 自带的Jquery
    var $= layui.$;
    var verifyCode=$("#verifyCode");
    verifyCode.attr("src","/BWM_war/kaptcha/kaptcha.jpg"+"?data="+new Date());
}

